<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body,html{
            width: 100%;
            height: 100%;
            
        }
        .box1{
            margin: 80px auto;
            width: 550px;
            height: 300px;
            /* padding: 5px; */
            box-sizing: border-box;
            background-color: lightblue;
        }
        .box2 li img{
            width: 550px;
            height: 300px;
            padding: 10px;
            box-sizing: border-box;  
        }
        .box2{
            width: 550px;
            height: 300px;
            position: relative;
            overflow: hidden;
            /* float: left; */
            /* box-sizing: border-box; */
            /* background-color: antiquewhite; */
        }
        .box2 ul {
            position:absolute;
            display: flex;
            /* left: 0px; */
            transition: 0.8s;
        }
        .box2 li{
            list-style: none;
            
        }
        .a_box{
            position:absolute;
            top: 270px;
            left: 30%;
        }
        .a_box a{
            position: relative;
            float: left;
            width: 20px;
            height: 20px;
            background-color: red; 
            margin: 0px 10px;
            opacity: 0.5;
        }
        .a_box a:hover{
            background-color: black;
        }
    </style>
</head>
<body>
    
<div class="box1">
    <div class="box2">
        <ul id="ulList">
            <li><img src="../img/1.jpg" alt=""></li>
            <li><img src="../img/2.jpg" alt=""></li>
            <li><img src="../img/3.jpg" alt=""></li>
            <li><img src="../img/4.jpg" alt=""></li>
            <li><img src="../img/5.jpg" alt=""></li>
        </ul>
        <div class="a_box">
            <a href="javascript:;"></a>
            <a href="javascript:;" ></a>
            <a href="javascript:;"></a>
            <a href="javascript:;" ></a>
            <a href="javascript:;" ></a>
        </div>
    </div>
</div>
<script>
    //获取ul
    let ul_list = document.getElementById('ulList');
    //获取a标签
    let aList = document.querySelectorAll('a');
    // alert(aList.length)
    
    setInterval(()=>{
        let leftValue = ul_list.offsetLeft;
        // alert(leftValue) //
        if(leftValue < -1650){
            leftValue = 550;
        }
        ul_list.style.left = leftValue - 550 +'px';
    },2000)

    var index =0;
    aList[index].style.backgroundColor = 'black';
    

    for(let i = 0;i < aList.length;i++){ 
        aList[i].onclick = function(){
            let change = -550*i; 
            // alert(change)
            ul_list.style.left = change + 'px'; 
            // console.log('1111');
            
        }
    };


</script>
</body>
</html>